<script setup>
import axios from "axios";
import {reactive, onMounted} from "vue";

let jsonData = reactive({
      "code": 1, "content": "我努力不是为了你而是因为你。"
    }
);
let getLoveMessage = async () => {
  let {data} = await axios.get(
      "http://forum.atguigu.cn/api/rand.qinghua?format=json", //请求地址
      {
        params: {id: 10, name: "zhangsan"} //参数
      }
  )
  console.log(data);
  ////对象合并 先写对象在写来源对象
  Object.assign(jsonData, data);
  console.log(123);
};
// 刷新页面获取一次
onMounted(() => {
  getLoveMessage();
})
</script>

<template>
  <div>
    <h1>AxiosTest</h1>
    <input type="text"><br/>
    <h2>今日情话：{{ jsonData.content }}</h2>
    <button @click="getLoveMessage">获取今日土味情话</button>
  </div>
</template>

<style scoped>

</style>